package com.hfdg.prototype.base.model;

import com.alibaba.fastjson.JSONObject;
import org.springframework.jdbc.core.RowMapper;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @ClassName FieldModel
 * @Description  数据库字段信息对应模型类
 * @Author yuelh
 * @Date 2020-4-24 18:04
 * @Version 1.0
 * @Company 会飞的锅工作室
 **/
public class FieldModel implements RowMapper<FieldModel>, Serializable {
    String fieldType;
    String fieldName;
    Integer length;
    String fieldComment;

    public String getFieldType() {
        return fieldType;
    }

    public void setFieldType(String fieldType) {
        this.fieldType = fieldType;
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getFieldComment() {
        return fieldComment;
    }

    public void setFieldComment(String fieldComment) {
        this.fieldComment = fieldComment;
    }

    public Integer getLength() {
        return length;
    }

    public void setLength(Integer length) {
        this.length = length;
    }

    @Override
    public FieldModel mapRow(ResultSet resultSet, int i) throws SQLException {
        FieldModel fieldModel = new FieldModel();
        fieldModel.setFieldName(resultSet.getString("column_name"));
        fieldModel.setFieldComment(resultSet.getString("column_comment"));
        fieldModel.setLength(resultSet.getInt("data_type"));
        fieldModel.setFieldType(resultSet.getString("data_type"));
        return fieldModel;
    }

    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }
}
